<?php
require("../../../dbconnect.php");

/* CONFIGURATION */
$module = "ip_manager";
error_reporting(0);

if (isset($_SESSION["adminid"]) && isset($_REQUEST["op"]))
{
	/* INITIALIZATION */
	$result = mysql_query("SELECT * FROM mod_config WHERE module='".$module."' ORDER BY config;");
	$cfgs = array();
	while ($cfg = mysql_fetch_assoc($result))
	{
		$cfgs[$cfg["config"]][] = $cfg["val"];
	}
	$shifts = explode(",", $cfgs["shifts"][0]);

	if ($_REQUEST["op"]=="get_history")
	{
		$historyTable = "<table cellspacing='1' cellpadding='3' border='0' width='100%' class='datatable' style='background: #CCC'><tr><th>User</th><th>Action</th><th>Time</th></tr>";
		
		if ($_REQUEST['type']=="vlan")
		{			
			$rs = mysql_query("SELECT mod_history.*, CONCAT(lastname, ' ', firstname) as username FROM mod_history LEFT JOIN tbladmins ON tbladmins.id = mod_history.uid WHERE tid = ".intval($_REQUEST['id'])." ORDER BY mod_history.logtime ASC;");
		
			if (mysql_num_rows($rs)>0)
			{
				while ($row = mysql_fetch_array($rs))
				{		
					$historyTable .= "<tr><td>".$row['username']."</td><td style='text-align: left'>".$row['action']."</td><td>".$row['logtime']."</td></tr>";		
				}
			}
			else
			{
				$historyTable .= "<tr><td colspan=3>No data found.</td></tr>";
			}										
		}else if ($_REQUEST['type']=="ip")	
		{
			$rs = mysql_query("SELECT mod_history.*, CONCAT(lastname, ' ', firstname) as user FROM mod_history LEFT JOIN tbladmins ON tbladmins.id = mod_history.uid WHERE tid = ".intval($_REQUEST['id'])." AND type = 'iplog' ORDER BY mod_history.id ASC;");
						
			if (mysql_num_rows($rs) > 0)
			{
				while ($row = mysql_fetch_array($rs))
				{
					$historyTable .= "<tr><td>".$row['user']."</td><td style='text-align: left'>".$row['action']."</td><td>".$row['logtime']."</td></tr>";
				}
			}else
			{
				$historyTable .= "<tr><td colspan=3>No Data Found</td></tr>";
			}						
		}		
		echo $historyTable .= "</table>";
	}
	else if ($_REQUEST["op"]=="remove_history")
	{
		$removeTable = "<table cellspacing='1' cellpadding='3' border='0' width='100%' class='datatable' style='background: #CCC'><tr><th>User</th><th>Action</th><th>Time</th></tr>";
		
		if ($_REQUEST['type']=="deletevlan")
		{				
			$rs = mysql_query("SELECT mod_history.*, CONCAT(lastname, ' ', firstname) as user FROM mod_history LEFT JOIN tbladmins ON tbladmins.id = mod_history.uid WHERE type ='deletevlan' ORDER BY mod_history.id;");
			
			if (mysql_num_rows($rs) > 0)
			{
				while ($row = mysql_fetch_array($rs))
				{
					$removeTable .= "<tr><td>".$row['user']."</td><td style='text-align: left'>".$row['action']."</td><td>".$row['logtime']."</td></tr>";
				}
			}else
			{
				$removeTable .= "<tr><td colspan=3>No Data Found</td></tr>";
			}	
		}
		else if ($_REQUEST['type']=="deleteip")
		{			
			$rs = mysql_query("SELECT mod_history.*, CONCAT(lastname, ' ', firstname) as user FROM mod_history LEFT JOIN tbladmins ON tbladmins.id = mod_history.uid WHERE type ='deleteip' ORDER BY mod_history.id;");
			
			if (mysql_num_rows($rs) > 0)
			{
				while ($row = mysql_fetch_array($rs))
				{
					$removeTable .= "<tr><td>".$row['user']."</td><td style='text-align: left'>".$row['action']."</td><td>".$row['logtime']."</td></tr>";
				}
			}else
			{
				$removeTable .= "<tr><td colspan=3>No Data Found</td></tr>";
			}	
		}
		
		echo $removeTable .= "</table>";
	}
}
?>